import traceback

import pytest

from autoTest_prtcApi.utils.log_util import logger

def assert_util(expect,compare,actual):
    """
    :param expect: 期望结果
    :param compare: 断言方式
    :param actual: 实际结果
    :return: 返回值
    """
    logger.info(f"断言数据：{expect} {compare} {actual}")
    try:
        if type(expect) != type(actual):
            raise NameError(f"expect:{expect}的数据类型是 {type(expect)},"
                            f"actual:{actual}的数据类型是{type(actual)}，数据类型不一致，无法比较")
        elif compare == "==":
            pytest.assume(expect == actual)
        elif compare == "!=":
            pytest.assume(expect != actual)
        elif compare == ">":
            pytest.assume(expect > actual)
        elif compare == ">=":
            pytest.assume(expect >= actual)
        elif compare == "<":
            pytest.assume(expect < actual)
        elif compare == "<=":
            pytest.assume(expect <= actual)
        elif compare == "in":
            pytest.assume(expect in actual)
        elif compare == "not in":
            pytest.assume(expect not in actual)
        else:
            raise NameError(f"对比方式 {compare} 输入有误，请确认.")
        logger.info(f"断言完成。。。。\n")
    except Exception as e:
            logger.error(f"断言失败，失败原因是：\n{e}")
            raise
